// JavaScript Document
var enterprise = {
	enterpriseCodeImg: '',
	legalCardImgA: '',
	legalCardImgB: '',
	real: function (data) {
		$.commonAjax({
			url: 'B044',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				$.alert(res.msg);
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}, enterprise_d: function () {
		$.commonAjax({
			url: 'B046',
			type: 'GET',
			data: {},
			isShowError: true,
			success: function (res) {
				console.log(res.data);
				console.log(res.data);
				$('input:eq(0)').val(res.data.enterpriseName);
				$('input:eq(1)').val(res.data.enterpriseCode);
				$('.uploadImg_1').html('<img src="'+CONFIG.imgUrl+res.data.enterpriseCodeImg+'" style="display:block;width:100%;">').show();
				$('.uploadImg_2').html('<img src="'+CONFIG.imgUrl+res.data.legalCardImgA+'" style="display:block;width:100%;">').show();
				$('.uploadImg_3').html('<img src="'+CONFIG.imgUrl+res.data.legalCardImgB+'" style="display:block;width:100%;">').show();
				$('.info:eq(2)').val(res.data.legalRealName);
				$('.info:eq(3)').val(res.data.legalIdentityCode);
				console.log(res.data.auditStatus == 1)
				if(res.data.auditStatus == 1){
					$('.subBtn').prop('disabled',true).val('已认证').css('background-color','gray');
				}
				 if(res.data.auditStatus != 0 && res.data.auditStatus != 1){
					$('.subBtn').prop('disabled',true).val('认证中').css('background-color','gray');
				 }
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	}

}
$(function () {
	enterprise.enterprise_d();
	$('input[id^="file_"]').change(function () {
		var num = $(this).prop('id').split('_')[1];
		var fd = new FormData();
		fd.append('fileType', 'enterprise');

		var reader = new FileReader();
		reader.readAsDataURL($(this)[0].files[0]);
		fd.append(0, $(this)[0].files[0]);
		$.ajax({
			url: CONFIG.apiUrl + '/upload/documentByH5.api',
			type: 'post',
			data: fd,
			processData: false,
			contentType: false,
			beforeSend: function () {
				if (layer)
					layer.closeAll('loading');
				$.layerload();
			},
			success: function (res) {
				if (layer)
					layer.closeAll('loading');
				if (res.code && res.code != 200) {
					$.layermsg(res.msg);
					return false;
				}
				var fileList = res.data;
				if (null == fileList || fileList.length == 0) {
					$.layermsg("文件上传失败");
					return false;
				}
				var urlZ = fileList[0].path;
				switch (Number(num)) {
					case 1:
						console.log(num);
						enterprise.enterpriseCodeImg = urlZ;
						$('.uploadImg_1').show();
						$('.uploadImg_1').html('<img src="' + CONFIG.imgUrl + urlZ + '" style="display:block;width:100%;">');
						break;
					case 2:
						enterprise.legalCardImgA = urlZ;
						$('.uploadImg_2').show();
						$('.uploadImg_2').html('<img src="' + CONFIG.imgUrl + urlZ + '" style="display:block;width:100%;">');
						break;
					case 3:
						enterprise.legalCardImgB = urlZ;
						$('.uploadImg_3').show();
						$('.uploadImg_3').html('<img src="' + CONFIG.imgUrl + urlZ + '" style="display:block;width:100%;">');
						break;
				}
				/*
				$("#"+_id).siblings("img").attr("src",CONFIG.imgUrl + urlZ);
				$("#"+_id).siblings("img").attr("filePath",urlZ);
				$("#"+_id).addClass("alphaClass");
				$("#"+_id).siblings("span").addClass("alphaClass"); */
			},
			error: function () {
				if (layer)
					layer.closeAll('loading');
				$.layermsg("图片上传异常，请重试");
			}
		})

		$('.subBtn').click(function () {
			var enterpriseName = $('.info:eq(0)').val();
			var enterpriseCode = $('.info:eq(1)').val();
			var legalRealName = $('.info:eq(2)').val();
			var legalIdentityCode = $('.info:eq(3)').val();
			var data = {
				enterpriseName: enterpriseName,
				enterpriseCode: enterpriseCode,
				legalRealName: legalRealName,
				legalIdentityCode: legalIdentityCode,
				enterpriseCodeImg: enterprise.enterpriseCodeImg,
				legalCardImgA: enterprise.legalCardImgA,
				legalCardImgB: enterprise.legalCardImgB
			};
			enterprise.real(data);
		});
	});
})